﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using Infrastructure;
////using eBook.Service;
namespace Gama.Website
{
    public class UserIdentity:IUserIdentity
    {
        #region IUserIdentity Members

        public Guid ID { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Role { get; set; }

        #endregion

        public UserIdentity CreateGuest()
        {
            //////var service = new SecurityService();
            UserIdentity guest = null;

            //////if (VisitContext.Cookie.GuestId.HasValue)
            //////{                
            //////    Guid guestId = VisitContext.Cookie.GuestId.Value;
            //////    if (service.ValidateGuest(guestId)) // client-side provided guest Id is valid?
            //////    {
            //////        guest = CreateGuestPrincipal(guestId);
            //////    }
            //////}
            //////// if client does not provide guest Id or the provided guest Id is not valid, create one
            //////if (guest == null)
            //////{
            //////    Guid guestId = service.CreateGuest();

            //////    // create guest
            //////    guest = CreateGuestPrincipal(guestId);
            //////}
            //////// persists client-side guest Id. If one has already existed, its timeout is reset
            //////VisitContext.Cookie.GuestId = guest.ID;

            return guest;
        }
        public UserIdentity CreateCustomer(Guid id, string firstName, string lastName, string role)
        {
            return new UserIdentity { ID = id, FirstName = firstName, LastName = lastName, Role = role};
        }
        private static UserIdentity CreateGuestPrincipal(Guid guestId)
        {
            UserIdentity guestIdentity = new UserIdentity { ID =guestId, FirstName=string.Empty, LastName = "Guest", Role ="Guest"};
            return guestIdentity;
        }
        public bool IsAuthenticated 
        { 
            get {
                return !string.IsNullOrEmpty(this.FirstName);
            } 
        }
    }
}